import Vuex from 'vuex';
import Vue from 'vue';
Vue.use(Vuex);
import * as types from './types';

const state={
    loginState: false,
    userInfo:{
        userName:"",
        userType:""
    }
};

const getters={};
const mutations={
    // 更新登陆状态
    [types.UPDATE_LOGIN_STATE](state,isLogin){
        state.loginState = isLogin || false;
    },
    //初始化用户信息
    [types.SET_USER_INFO](state,userInfo){
        state.userInfo = {...userInfo};
    }
};
const actions={
    changeLoginState({ commit },isLogin,userInfo){
        commit(types.UPDATE_LOGIN_STATE,isLogin);
        commit(types.SET_USER_INFO,userInfo);
    }
};

const store = new Vuex.Store({
    // strict: true,
    state,
    getters,
    mutations,
    actions
});

export default store;